<?php
if(defined("IZ_ACCNAME")) {
      if($_SESSION['MYSQLi']) {
        global $dblink;
        $sqlver = $dblink->server_version;
        if(version_compare((string)$sqlver,"4.1","<")) {
          @$dblink->query("SET NAMES 'utf8'");
        }
      } else {
        $sqlver = ereg_replace("[^0-9\.]", "", mysql_get_server_info());
        if(version_compare((string)$sqlver,"4.1","<")) {
          @mysql_query("SET NAMES 'utf8'");
        }
      }
    if(version_compare((string)$sqlver,"4.1","<")) {
      $createcats = "CREATE TABLE IF NOT EXISTS `categories` (
        `id` VARCHAR( 8 ) NOT NULL,
        `name` TEXT NOT NULL,
        `owner` TEXT NOT NULL,
        `type` TEXT NOT NULL,
        `public` INT NOT NULL DEFAULT '1',
        `color` TEXT NOT NULL,
            PRIMARY KEY  (`id`)) ENGINE = MYISAM;";
      $createcomments = "CREATE TABLE IF NOT EXISTS `comments` (
        `id` varchar(8) NOT NULL,
        `postid` varchar(8) NOT NULL,
        `author` TEXT NOT NULL,
        `posted` int(11) NOT NULL DEFAULT '0',
        `text` TEXT NOT NULL,
            PRIMARY KEY (`id`)) ENGINE=MyISAM;";
      $createevents = "CREATE TABLE IF NOT EXISTS `events` (
        `id` VARCHAR( 8 ) NOT NULL,
        `category` TEXT NOT NULL,
        `eventstart` INT( 11 ) NOT NULL DEFAULT '0',
        `eventend` INT( 11 ) NOT NULL DEFAULT '0',
        `title` TEXT NOT NULL,
        `description` TEXT NOT NULL,
        `venue` TEXT NOT NULL,
        `linkgoogle` INT( 1 ) NOT NULL DEFAULT '0',
        `allday` INT( 1 ) NOT NULL DEFAULT '0',
        `instanceof` TEXT NOT NULL,
        `status` TEXT NOT NULL,
        `author` TEXT NOT NULL,
        `cust1` TEXT NOT NULL,
        `cust2` TEXT NOT NULL,
        `cust3` TEXT NOT NULL,
        `attendees` TEXT NOT NULL,
        `comments` INT ( 1 ) NOT NULL DEFAULT '1',
        `icon` INT ( 2 ) DEFAULT '-1',
            PRIMARY KEY ( `id` )) ENGINE = MYISAM;";
      $createsettings = "CREATE TABLE IF NOT EXISTS `settings` (
        `name` VARCHAR( 30 ) NOT NULL,
        `setval` TEXT NOT NULL,
            UNIQUE (`name`)) ENGINE = MYISAM;";
      $createtodo = "CREATE TABLE IF NOT EXISTS `tasks`(
        `id` VARCHAR( 8 ) NOT NULL,
        `category` TEXT NOT NULL,
        `created` INT( 11 ) NOT NULL DEFAULT '0',
        `due` INT( 11 ) NOT NULL DEFAULT '0',
        `title` TEXT NOT NULL,
        `description` TEXT NOT NULL,
        `author` TEXT NOT NULL,
        `complete` INT( 1 ) NOT NULL, 
        `cust1` TEXT NOT NULL,
        `cust2` TEXT NOT NULL,
        `cust3` TEXT NOT NULL,
        `status` TEXT NOT NULL,
        `comments` INT ( 1 ) NOT NULL DEFAULT '1',
        `icon` INT ( 2 ) DEFAULT '-1',
            PRIMARY KEY  (`id`)) ENGINE = MYISAM ;";
      $createusers = "CREATE TABLE IF NOT EXISTS `users`(
        `id` VARCHAR( 8 ) NOT NULL,
        `name` TEXT NOT NULL,
        `usergroup` TEXT NOT NULL,
        `password` TEXT NOT NULL,
        `language` TEXT NOT NULL,
        `daysize` TEXT NOT NULL,
        `firstdayofweek` INT NOT NULL DEFAULT '0',
        `theme` TEXT NOT NULL, 
        `defaultstatus` TEXT NOT NULL,
        `showall` INT NOT NULL DEFAULT '1', 
        `dateformat` TEXT NOT NULL,
        `defaultcategoryevents` TEXT NOT NULL,
        `defaultcategorytasks` TEXT NOT NULL,
        `pageafter` INT NOT NULL DEFAULT '30',
        `fontsize` TEXT NOT NULL,
        `collapsestatus` TEXT NOT NULL,
        `color` TEXT NOT NULL,
        `viewdetails` INT NOT NULL DEFAULT '1',
        `includecomplete` INT NOT NULL DEFAULT '1',
            PRIMARY KEY  (`id`)) ENGINE = MYISAM ;";
    } else {
      $createcats = "CREATE TABLE IF NOT EXISTS `categories` (
        `id` VARCHAR( 8 ) NOT NULL,
        `name` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `owner` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `type` TEXT NOT NULL,
        `public` INT NOT NULL DEFAULT '1',
        `color` TEXT NOT NULL,
            PRIMARY KEY  (`id`)) ENGINE = MYISAM;";
      $createcomments = "CREATE TABLE IF NOT EXISTS `comments` (
        `id` varchar(8) NOT NULL,
        `postid` varchar(8) NOT NULL,
        `author` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `posted` int(11) NOT NULL DEFAULT '0',
        `text` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
            PRIMARY KEY (`id`)) ENGINE=MyISAM;";
      $createevents = "CREATE TABLE IF NOT EXISTS `events` (
        `id` VARCHAR( 8 ) NOT NULL,
        `category` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `eventstart` INT( 11 ) NOT NULL DEFAULT '0',
        `eventend` INT( 11 ) NOT NULL DEFAULT '0',
        `title` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `venue` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `linkgoogle` INT( 1 ) NOT NULL DEFAULT '0',
        `allday` INT( 1 ) NOT NULL DEFAULT '0', 
        `instanceof` TEXT NOT NULL,
        `status` TEXT NOT NULL,
        `author` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL, 
        `cust1` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `cust2` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `cust3` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `attendees` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `comments` INT ( 1 ) NOT NULL DEFAULT '1',
        `icon` INT ( 2 ) NOT NULL DEFAULT '-1',
            PRIMARY KEY ( `id` )) ENGINE = MYISAM;";
      $createsettings = "CREATE TABLE IF NOT EXISTS `settings` ( 
        `name` VARCHAR( 30 ) NOT NULL,
        `setval` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
            UNIQUE (`name`)) ENGINE = MYISAM;";
      $createtodo = "CREATE TABLE IF NOT EXISTS `tasks` (
        `id` VARCHAR( 8 ) NOT NULL,
        `category` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `created` INT( 11 ) NOT NULL DEFAULT '0',
        `due` INT( 11 ) NOT NULL DEFAULT '0',
        `title` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `description` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `author` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `complete` INT( 1 ) NOT NULL,
        `cust1` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `cust2` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `cust3` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `comments` INT ( 1 ) NOT NULL DEFAULT '1',
        `status` TEXT NOT NULL,
        `icon` INT ( 2 ) NOT NULL DEFAULT '-1',
            PRIMARY KEY  (`id`)) ENGINE = MYISAM ;";
      $createusers = "CREATE TABLE IF NOT EXISTS `users`(
        `id` VARCHAR( 8 ) NOT NULL,
        `name` TEXT CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
        `usergroup` TEXT NOT NULL,
        `password` TEXT NOT NULL,
        `language` TEXT NOT NULL,
        `daysize` TEXT NOT NULL,
        `firstdayofweek` INT NOT NULL DEFAULT '0',
        `theme` TEXT NOT NULL,
        `defaultstatus` TEXT NOT NULL,
        `showall` INT NOT NULL DEFAULT '1', 
        `dateformat` TEXT NOT NULL,
        `defaultcategoryevents` TEXT NOT NULL,
        `defaultcategorytasks` TEXT NOT NULL,
        `pageafter` INT NOT NULL DEFAULT '30',
        `fontsize` TEXT NOT NULL,
        `collapsestatus` TEXT NOT NULL,
        `color` TEXT NOT NULL,
        `viewdetails` INT NOT NULL DEFAULT '1', 
        `includecomplete` INT NOT NULL DEFAULT '1', 
            PRIMARY KEY  (`id`)) ENGINE = MYISAM ;";
    }
    $creategroups = "CREATE TABLE IF NOT EXISTS `groups`(
      `id` VARCHAR( 8 ) NOT NULL,
      `name` TEXT NOT NULL,
      `view` INT NOT NULL DEFAULT '1',
      `edit` INT NOT NULL DEFAULT '1',
      `delete` INT NOT NULL DEFAULT '1',
      `cpanel` INT NOT NULL DEFAULT '1',
      `customise` INT NOT NULL DEFAULT '1',
      `comment` INT NOT NULL DEFAULT '1',
            PRIMARY KEY  (`id`)) ENGINE = MYISAM ;";
    $inscats = "INSERT INTO categories (`id`, `name`, `owner`, `type`,`public`,`color`) VALUES
      ('psdfsgtr','".STR_EVENTS."','everyone','event','1','#FFF6CF'),
      ('ufbqdfkr','".STR_TASKS."','everyone','task','1','#FFF6CF');";
    $insusers = "INSERT INTO users (`id`,`name`,`usergroup`,`password`,`language`,`daysize`,`firstdayofweek`,`theme`,`defaultstatus`,`showall`,`dateformat`,`defaultcategoryevents`,`defaultcategorytasks`,`pageafter`,`fontsize`,collapsestatus,color,viewdetails,includecomplete) VALUES
      ('ifhhn90s','$adminuser','ijklmnip','$md5pass','$lang','small','0','default','Public','1','d-m-y','psdfsgtr','ufbqdfkr','30','medium','0-0-1','default','1','1'),
      ('ifhhn99s','usermask','ijklmnip','".saltpassword('1')."','en', 'small', '0', 'default', 'Public','1','d-m-y','','','30','medium','0-0-1','default','1','1'),
      ('zzzzzzzz','everyone','abcdefgh','','$lang','small','0','default','Public','1','d-m-y','psdfsgtr','ufbqdfkr','30','medium','0-0-1','default','1','1');";
    $insgroups = "INSERT INTO groups (`id`,`name`,`view`,`edit`,`delete`,`cpanel`,`comment`,`customise`) VALUES
      ('ijklmnip','".STR_ADMINISTRATORS."','1','2','2','1','1','1'),
      ('abcdefgh','".STR_GUESTS."','1','1','1','0','1','1');";
    $inssettings = "INSERT INTO settings (`name`, `setval`) VALUES
      ('IZ_CALURL', '$calurl'),
      ('IZ_REPLACELOGO','0'),
      ('IZ_CURTHEME', 'default'),
      ('IZ_ALLOWCOMMENTS','1'),
      ('IZ_OPT','4095'),
      ('IZ_NV','8191'),
      ('IZ_DEFAULTGROUP','abcdefgh'),
      ('IZ_REWRITE','0'),
      ('IZ_LANG', '$lang'),
      ('IZ_FIRSTDAY', '0'),
      ('IZ_MVIEWDAYSIZE', 'small'),
      ('IZ_CALNAME', '$calendarname'),
      ('IZ_TIMEOFFSET', '0'),
      ('IZ_INVITEMODE', 'php'),
      ('IZ_GMAIL_ACC', ''),
      ('IZ_GMAIL_PWD', ''),
      ('IZ_DEFNUMRECS', '10'),
      ('IZ_DEFAULTVIEW', 'month'),
      ('IZ_ITEMCOLORS', 'c'),
      ('cust1', 'none'),
      ('cust2', 'none'),
      ('cust3', 'none'),
      ('cust_pagebg', ''),
      ('cust_calbg', ''),
      ('cust_occbg', ''),
      ('cust_occtext', ''),
      ('cust_blankbg', ''),
      ('cust_blanktext', ''),
      ('cust_todaybg', ''),
      ('cust_todaytext', ''),
      ('cust_fillerdays', ''),
      ('cust_calwrappertext', ''),
      ('cust_boxbg', ''),
      ('cust_boxtext', ''),
      ('cust_othertext', '');";
} else {
  // Directly accessed
  header('Location: ../');
} ?>